#Config variables:
binmode=755
filemode=644
uid=root
gid=root
wwwuid=www-data
wwwgid=www-data

all: install link

mkinstalldirs:
	@ echo -e "Creating directory structure....Done"
	@install -d $(DESTDIR)/usr/lib/cgi-bin/yalw/ -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/etc/yalw/ -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/usr/share/yalw/ -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/usr/share/yalw/web -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/usr/share/yalw/web/themes/ -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/usr/share/yalw/web/images/ -m $(binmode) -o $(uid) -g $(gid)
	@install -d $(DESTDIR)/usr/share/perl5/yalw/ -m $(binmode) -o $(uid) -g $(gid) 
	@install -d $(DESTDIR)/usr/share/yalw/plugins/ -m $(binmode) -o $(wwwuid) -g $(wwwgid)

install: mkinstalldirs
	@echo -e "Installing binary files....Done\nInstalling normal files....Done"  
	@install -m $(binmode)  -g $(gid) -o $(uid) src/config $(DESTDIR)/etc/yalw/
	@install -m $(binmode)  -g $(gid) -o $(uid) src/themes/* /usr/share/yalw/web/themes/
	@install -m $(binmode)  -g $(gid) -o $(uid) src/images/* /usr/share/yalw/web/images/
	@install -m $(binmode)  -g $(gid) -o $(uid) src/index.html /usr/share/yalw/web/
	@install -m $(binmode)  -g $(gid) -o $(uid) src/yalw.pm /usr/share/perl5/yalw/
	@install -m $(binmode)  -g $(wwwgid) -o $(wwwuid) src/plugins/* /usr/share/yalw/plugins/

link:
	@echo -e "Linking....Done"
	@ln -s /usr/share/yalw/web /var/www/yalw
	@ln -s /etc/yalw/config /usr/lib/cgi-bin/yalw/index.pl 

uninstall:
	@echo -e "Removing files....Done\nRemoving links....Done\nRemoving Dirs....Done"
	@rm -rf $(DESTDIR)/usr/lib/cgi-bin/yalw
	@rm -rf $(DESTDIR)/usr/share/yalw
	@rm -rf $(DESTDIR)/usr/share/perl5/yalw
	@rm -rf $(DESTDIR)/etc/yalw
	@rm     $(DESTDIR)/var/www/yalw

